
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>

int main( int argc, char * argv[] )
{
	assert( argc == 3 );
	char * sourceName = argv[ 1 ];
	char * functionName = argv[ 2 ];
	FILE *fIn = fopen( sourceName, "r" );
	assert( fIn );
	char sinkName[ 1024 ];
	sprintf( sinkName, "%s.cpp", sourceName );
	FILE *fOut = fopen( sinkName, "w" );
	assert( fOut );

	fprintf( fOut, "#include \"pipeline-kit.hpp\"\n" );
	fprintf( fOut, "#include <string>\n" );
	fprintf( fOut, "std::string %s( void ){\n", functionName );
	fprintf( fOut, "return\n" );
	char buffer[ 1024 ];
	while( !feof( fIn ) ){
		fgets( buffer, sizeof( buffer ), fIn );
		if( feof( fIn )){
			break;
		}
		int length = strlen( buffer );
		assert( length < sizeof( buffer ) - 3 );
		fprintf( fOut, "\"" );
		for( unsigned int i = 0; i < strlen( buffer ); ++i ){
			if( !isprint( buffer[ i ] )) continue;
			if( buffer[ i ] == '\"' ){
				fprintf( fOut, "\\\"" );
			}
			else if( buffer[ i ] == '\'' ){
				fprintf( fOut, "\\'" );
			}
			else if( buffer[ i ] == '\\' ){
				fprintf( fOut, "\\\\" );
			}
			else{
				fprintf( fOut, "%c", buffer[ i ] );
			}
		}//for
		fprintf( fOut, "\\n\"\n" );
	}//while

	fprintf( fOut, ";\n" );
	fprintf( fOut, "}\n" );
	fclose( fIn );
	fclose( fOut );
}
